package com.linln.modules.member.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import com.linln.modules.member.domain.MemberPayDayCount;


/**
 * @author hct
 * @date 2019/09/12
 */
public interface MemberPayDayCountRepository extends JpaRepository<MemberPayDayCount, Long> ,JpaSpecificationExecutor<MemberPayDayCount>{
	
	/**
	 * 定时执行数据  
	 * @return
	 */
    @Transactional
    @Modifying
	@Query(value="INSERT INTO member_pay_daycount(area,num,create_date,update_date) SELECT area,sum(money), DATE_SUB(CURDATE(), INTERVAL 1 DAY),now() FROM member_order where to_days(create_date) = to_days(DATE_SUB(curdate(),INTERVAL 1 DAY)) and pay_status=1 group by area ",nativeQuery = true)
	public Integer insert();

	@Transactional
	@Query(value=" select count(*) FROM member_pay_daycount where to_days(create_date) = to_days(DATE_SUB(curdate(),INTERVAL 1 DAY))  ",nativeQuery = true)
	public Integer dayCount();
}